1. Field of the Invention
The present invention relates generally to accessing files stored on a storage volume via application programming interfaces, and more particularly to interfacing index based and iterator based application programming interfaces.
2. Description of the Background Art
Computer file management routines for accessing directory entries in file systems are typically either index based or iterator based. Index based file management routines access directory entries according to an index number, normally an integer, associated with a particular entry. Iterator based routines, in contrast, access directory entries suing an iterator, which contains state information.
Index based routines, in some implementations, begin searching at the beginning (or at the xe2x80x9ctopxe2x80x9d) of the directory each time an index based search request is received. Because this implementation is typically highly inefficient, improved index based routines have been developed that record a single most recently used (MRU) index. The MRU index is usually maintained internally, which tends to limit the number of clients that can effectively use the index based routine during the same time period. Indeed, conventional index based routines maintain a single MRU per directory. Such, index based routines that merely record the MRU index can be problematic where more than one application is accessing the same directory at substantially the same time or where an application is accessing multiple directories at substantially the same time.
In the circumstance where multiple applications are accessing entries of a single directory at substantially the same time, the MRU index of one application may be replaced by the MRU index of another application. Thus, because only a single MRU index is recorded, one application may be relying on the index most recently used by another application instead of on its own MRU index and vice versa, thus frustrating any advantage obtained by recording the MRU index.
A similar problem arises where a single application is accessing multiple directories during the same time period. In this circumstance, where the MRU index is within one directory, and the application then needs to access an entry located in another directory, the index based routine will begin searching from the first entry in the other directory without the benefit of a MRU index within that directory. This, again, frustrates any advantage obtained by maintaining a single MRU index.
As mentioned above, iterator based routines access a requested directory entry using state information based on an iterator associated with the MRU directory entry. An iterator has three primary operations, namely (1) initialize, or point to the first item in the directory; (2) go to the next item in the directory; and (3) go to the previous item in the directory. Since the client maintains the state information, multiple clients can simultaneously access a directory using their own iterator. The iterator based routine, then, locates the requested entry by beginning at the entry associated with the iterator and stepping forward or backward as necessary to reach the requested directory, thus obviating the need to begin searching at the beginning of the directory each time a directory entry is requested.
For example, instead of submitting an index based request in the form of an integer, an iterator based routine typically receives a request for a directory entry with reference to an iterator associated with the most recently used entry. With the iterator as a reference, the requested entry may then be located by merely stepping up or down the directory from the iterator.
A problem arises, however, where an index based Applications Programming Interface (API), which does not use state information, is associated with an iterator based file management routine or an iterator based API, which does use state information. In this circumstance, the index based API requests a directory entry from an iterator based API or file manager by submitting an index based request in the form of an integer. Upon receipt of an index based request, conventional iterator based routines typically resort to the considerably less efficient index based approach and begin with the first directory entry and step through each entry until the requested entry is found. This approach has been largely unsatisfactory in that it is highly inefficient and, therefore, may cause significant performance problems.
Consequently, a need exists to provide a system and method for effectively and efficiently interfacing index based and iterator based file management routines. Moreover, a need exists for a system and method by which a directory entry may be accessed effectively and efficiently by an iterator based file management routine from an index based request.
The present invention overcomes or substantially alleviates prior problems associated with interfacing index based and iterator based routines. In general, the present invention maintains an iterator cache memory having multiple iterators. Each active iterator is associated with a specific directory entry. Upon receiving an index based request, the iterator closest to the index based request is identified. Once the closest iterator is identified, directory entries are examined sequentially beginning with the directory entry associated with the closest iterator and continuing until the directory entry associated with the index based request is located. In this manner, iterator based routines may efficiently locate directory entries from index based requests with a higher efficiency than by sequencing through all the directory entries beginning from the first directory entry each time an index based request is received.
The iterator closest to the-index based request is determined by calculating the absolute value of the difference between the index based request and an index number associated with each active iterator in the iterator cache. The active iterator having the smallest absolute value difference is deemed to be the iterator closest to the index based request.
Preferably, where the index based request is closer to the first directory entry than to the closest active iterator, the invention initializes an iterator and sequences through the directory entries beginning with the first directory entry rather than with the closest directory entry. In other words, in this embodiment, where the directory entry associated with the index based request is farther away (in absolute distance) from the closest active iterator than from the first directory entry, the invention begins to search sequentially beginning from the first directory entry instead of from the closest iterator.
In practice, it has been found that many applications tend to request directory entries in a substantially sequential fashion. That is, for example, after having just requested the twenty-fifth directory entry, an application will typically next request the twenty-sixth, or perhaps the twenty-seventh, directory entry. It is much less likely, in practice, for an application to request the sixteenth entry immediately following a request for the twenty-fifth entry.
Thus, by maintaining an iterator at the most recently used entry, the next entry may be quickly and efficiently accessed by sequencing through the directory entries beginning at that most recently used entry. Similarly, by stepping sequentially through the directory entries beginning with the first entry only when the closest iterator farther from the requested entry than the first entry, the invention permits entries near the top of the directory, or elsewhere within the directory, to be located efficiently. Further, by maintaining multiple iterators within an iterator cache, many problems associated with interfacing index based and iterator based routines are overcome or substantially alleviated.
Other advantages and features of the present invention will be apparent from the drawings and detailed description as set forth below.